package cn.gz.demo.ui.tab_fragment;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.Fragment;

import javax.annotation.Nullable;

import cn.gz.demo.R;
import cn.gz.demo.databinding.TabTestBinding;
import cn.gz.demo.utils.DisplayUtil;
import cn.gz.demo.view.CustomViewpager;

/**
 * Created by Lyz on 2017/3/8.
 */
@SuppressLint("ValidFragment")
public class TestFrament extends Fragment {
    private TabTestBinding binding;
    private View view;
    private Context context;
    private CustomViewpager viewpager;
    private int index;

    public TestFrament(CustomViewpager tabViewpager, int pos) {
        this.viewpager = tabViewpager;
        this.index = pos;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.tab_test_fragment, container, false);
        context = getContext();
        view = binding.getRoot();
        viewpager.setObjectForPosition(view, index);//添加这句（1代表的是该Fragment对象在ViewPager的位置）
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        binding.tabFragmentTv.setText("首页");
        binding.tabFragmentTv.setMinHeight(DisplayUtil.dip2px(context, 100 * (index + 1) / 2));
    }
}
